from django.db import models

# Create your models here.

# 会员模型
class Users(models.Model):
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=100)
    phone = models.CharField(max_length=11)
    face_url = models.CharField(max_length=100,default='/static/myadmin/img/de_WOW.png')
    sex = models.IntegerField(null=True)
    age = models.IntegerField(null=True)
    addtime = models.DateTimeField(auto_now_add=True)
    logintime = models.DateTimeField(auto_now=True)
    status = models.IntegerField(default=0)

# 商品分类模型
class BookType(models.Model):
    name = models.CharField(max_length=10)
    pid = models.IntegerField()
    path = models.CharField(max_length=50)

# 图书商品模型
class Books(models.Model):
    classifyid = models.ForeignKey('BookType',on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    subhead = models.CharField(max_length=255)
    author = models.CharField(max_length=100)
    publisher = models.CharField(max_length=100)
    pub_date = models.DateField()
    price = models.FloatField()
    num = models.IntegerField(default=1000)
    ISBN = models.CharField(max_length=13)
    context = models.TextField()

# 图书封面图模型
class BookImgs(models.Model):
    bookid = models.ForeignKey('Books',on_delete=models.CASCADE)
    img_url = models.CharField(max_length=100)

# 购物车模型
class Cart(models.Model):
    uid = models.ForeignKey('Users',on_delete=models.CASCADE)
    bid = models.ForeignKey('Books',on_delete=models.CASCADE)
    num = models.IntegerField()
    status = models.IntegerField(default=0)

# 订单模型
class Order(models.Model):
    uid = models.ForeignKey('Users',on_delete=models.CASCADE)
    name = models.CharField(max_length=50)
    phone = models.CharField(max_length=11)
    city = models.CharField(max_length=50)
    address = models.CharField(max_length=50)
    totalprice = models.FloatField()
    remark = models.CharField(max_length=255,null=True)
    status = models.IntegerField(default=0)
    ordertime = models.DateTimeField(auto_now_add=True)
    paytime = models.DateTimeField(null=True)

# 订单详情模型
class OrderDetails(models.Model):
    orderid = models.ForeignKey('Order',on_delete=models.CASCADE)
    bid = models.ForeignKey('Books',on_delete=models.CASCADE)
    num = models.IntegerField()
    price = models.FloatField()



